home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* EXPORT msg command *)
- (* *)
- (* Copyright 1988, 1989, 1990, 1991, 1992 by H. Roy Engehausen. All *)
- (* rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$UNDEF DEBUG_1}
- {$UNDEF DEBUG_FILE}
- {$UNDEF DEBUG_FILE2}
-
- {$O+}
-
- UNIT BBEXPORT;
-
- INTERFACE
-
- USES
- bbfwdd;
-
- PROCEDURE export_cmd(cmd_string : STRING; this_path : path_block_ptr);
-
- IMPLEMENTATION
-
- USES
- DOS,
- bbdummy,
- bbkmc,
- bbmdata,
- bbmess,
- bbmf,
- bbmisc,
- bbmisc2,
- bbmisc4,
- bbmisc5,
- bbmmsgn,
- bbsdata,
- bbsearch,
- bbsema2,
- bbstr,
- bbtask,
- bbtime;
-
- (*===========================================================================*)
- (* Export command *)
- (*===========================================================================*)
-
- PROCEDURE export_cmd(cmd_string : STRING; this_path : path_block_ptr);
-
- VAR
- add_header : BOOLEAN;
- b : BOOLEAN;
- export_in : TEXT;
- export_out : TEXT;
- exec_char : CHAR;
- i : INTEGER;
- kill_sw : BOOLEAN;
- msg_ptr : msg_index_ptr;
- out_open : BOOLEAN;
- search_block : search_block_type;
- save_ptr : POINTER;
- save_len : WORD;
- word_count : BYTE;
- work_word : STRING[20];
- x_msg_no : LONGINT;
-
- (*=========================================================================*)
- (* Cleanup detail *)
- (*=========================================================================*)
-
- PROCEDURE export_clean;
-
- BEGIN;
-
- {$IFDEF DEBUG_1}
- WRITELN('Clean export 1 -- ', out_open);
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Obtain the interrupt lock *)
- (*---------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*---------------------------------------------------------------------*)
- (* Close the output file if it is open *)
- (*---------------------------------------------------------------------*)
-
- IF out_open THEN
- BEGIN;
- {$I-}
- CLOSE(export_out);
- {$I+}
- out_open := FALSE;
- END;
-
- (*---------------------------------------------------------------------*)
- (* Release the interrupt lock *)
- (*---------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_1}
- WRITELN('Clean export 2 -- ', out_open);
- {$ENDIF}
-
- free_semaphore(semaphore_interrupts);
-
- END;
-
- (*=========================================================================*)
- (* Export a single message *)
- (*=========================================================================*)
-
- PROCEDURE export_a_msg (msg_ptr : msg_index_ptr);
-
- VAR
- b : BOOLEAN;
- i : INTEGER;
- m_no : STRING[5];
- t_str : STRING;
-
- BEGIN;
-
- {$IFDEF DEBUG_FILE2}
- WRITELN('Open_check = ', out_open);
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* If output file is not open then open it *)
- (*---------------------------------------------------------------------*)
-
- IF NOT out_open THEN
- BEGIN;
-
- (*-----------------------------------------------------------------*)
- (* Obtain the interrupt lock *)
- (*-----------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------*)
- (* Open output file. Try append mode first and then rewrite. *)
- (*-----------------------------------------------------------------*)
-
- {$I-}
- APPEND(export_out);
- i := IORESULT;
- {$I+}
- IF i = 2 THEN
- BEGIN;
- {$I-}
- REWRITE(export_out);
- i := IORESULT;
- {$I+}
- END;
- {$I+}
-
- {$IFDEF DEBUG_FILE2}
- WRITELN('Open results = ', i);
- {$ENDIF}
-
- (*-----------------------------------------------------------------*)
- (* Release the interrupt lock *)
- (*-----------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------*)
- (* Handle I/O error *)
- (*-----------------------------------------------------------------*)
-
- IF i <> 0 THEN
- BEGIN;
- IF i <> 2 THEN
- send_tnc_data_str(dos_err_message(i) + cr)
- ELSE
- send_tnc_data_str('Invalid file name' + cr);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------*)
- (* Show open output file *)
- (*-----------------------------------------------------------------*)
-
- out_open := TRUE;
-
- END; (*----- End opening output file --------------------------------*)
-
- (*---------------------------------------------------------------------*)
- (* Switch *)
- (*---------------------------------------------------------------------*)
-
- task_switch;
-
- (*---------------------------------------------------------------------*)
- (* Setup *)
- (*---------------------------------------------------------------------*)
-
- active_tcb^.curr_msg := msg_ptr^;
-
- WITH msg_ptr^.msg_i_mb DO
- BEGIN;
-
- (*-----------------------------------------------------------------*)
- (* Build the send command *)
- (*-----------------------------------------------------------------*)
-
- t_str := 'S' + msg_type + ' ' + msg_to;
-
- IF msg_to_at <> '' THEN
- BEGIN;
- t_str := t_str + ' @ ' + msg_to_at;
- IF msg_to_h <> '' THEN
- t_str := t_str + '.' + msg_to_h;
- END;
-
- t_str := t_str + ' < ' + msg_from;
-
- IF msg_bid <> '' THEN
- t_str := t_str + ' $' + msg_bid;
-
- (*-----------------------------------------------------------------*)
- (* Write the send command *)
- (*-----------------------------------------------------------------*)
-
- WRITELN(export_out, t_str);
-
- (*-----------------------------------------------------------------*)
- (* Write the subject *)
- (*-----------------------------------------------------------------*)
-
- WRITELN(export_out, msg_subj);
-
- (*-----------------------------------------------------------------*)
- (* Do we write a header? *)
- (*-----------------------------------------------------------------*)
-
- IF add_header AND (NOT opt_block.opt_personal_bbs) THEN
- BEGIN;
-
- (*-------------------------------------------------------------*)
- (* Time zone correction to header is send in proper time *)
- (*-------------------------------------------------------------*)
-
- INC(active_tcb^.curr_msg.msg_i_mb.msg_dt_in,
- opt_block.z_time_fwd);
- INC(active_tcb^.curr_msg.msg_i_mb.msg_dt_orig,
- opt_block.z_time_fwd);
-
- (*-------------------------------------------------------------*)
- (* Send the new forward header line. *)
- (*-------------------------------------------------------------*)
-
- IF ((msg_from_at = opt_block.this_bb_addr)
- OR ((msg_flag AND mf_bid_change)<>0))
- AND NOT opt_block.opt_no_alt_header THEN
- t_str := get_message(message_alt_header)
- ELSE
- t_str := get_message(message_fwd_head);
-
- WRITELN(export_out, t_str);
-
- END; (*----- End writing a header -------------------------------*)
-
- (*-----------------------------------------------------------------*)
- (* Build the dataset name *)
- (*-----------------------------------------------------------------*)
-
- STR(msg_number, m_no);
-
- t_str := opt_block.msg_file_dir + 'BB' + m_no + '.MSG';
-
- (*-----------------------------------------------------------------*)
- (* Open the file *)
- (*-----------------------------------------------------------------*)
-
- ASSIGN(export_in, t_str);
-
- {$I-}
- RESET(export_in);
- {$I+}
-
- i := IORESULT;
-
- (*-----------------------------------------------------------------*)
- (* Handle error on OPEN *)
- (*-----------------------------------------------------------------*)
-
- IF i <> 0 THEN
- BEGIN;
- t_str := t_str + ' -- ' + dos_err_message(i);
- WRITELN(export_out, t_str);
- send_tnc_data_str(t_str + cr);
- active_tcb^.error_sw := TRUE;
-
- {$IFDEF DEBUG_1}
- WRITELN('Error set open -- ', out_open);
- {$ENDIF}
-
- EXIT;
- END;
-
- (*-----------------------------------------------------------------*)
- (* Copy the file *)
- (*-----------------------------------------------------------------*)
-
- b := TRUE;
-
- i := 0;
-
- WHILE NOT EOF(export_in) DO
- BEGIN;
-
- IF i > 20 THEN
- BEGIN;
- task_switch;
- i := 0;
- END;
-
- b := EOLN(export_in);
-
- IF b THEN
- BEGIN;
- READLN(export_in, t_str);
- WRITELN(export_out, t_str);
- END
- ELSE
- BEGIN;
- READ(export_in, t_str);
- WRITE(export_out, t_str);
- END;
-
- END;
-
- (*-----------------------------------------------------------------*)
- (* Write the end of the file *)
- (*-----------------------------------------------------------------*)
-
- IF NOT b THEN
- WRITELN(export_out);
- WRITELN(export_out, '/EX');
-
- (*-----------------------------------------------------------------*)
- (* Close up *)
- (*-----------------------------------------------------------------*)
-
- CLOSE(export_in);
-
- (*-----------------------------------------------------------------*)
- (* Flush the buffers *)
- (*-----------------------------------------------------------------*)
-
- flushdosfile(@export_out);
-
- (*-----------------------------------------------------------------*)
- (* Report *)
- (*-----------------------------------------------------------------*)
-
- send_tnc_data_str('Message ' + m_no + ' exported' + cr);
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* Kill as needed *)
- (*---------------------------------------------------------------------*)
-
- IF kill_sw THEN
- kill_a_msg(msg_ptr, TRUE);
-
- END; (*----- End export a single message --------------------------------*)
-
- (*=========================================================================*)
- (* This is the code for exporting via a command search *)
- (*=========================================================================*)
-
- PROCEDURE do_export;
-
- BEGIN;
-
- CASE exec_char OF
-
- (*-------------------------------------------------------------------*)
- (* Export message by number *)
- (*-------------------------------------------------------------------*)
-
- '#' : BEGIN;
-
- (*------------------------------------------------------------*)
- (* Check word count -- must have something after the # *)
- (*------------------------------------------------------------*)
-
- IF word_count < 4 THEN
- BEGIN;
- send_message(message_not_en);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*------------------------------------------------------------*)
- (* Validate number *)
- (*------------------------------------------------------------*)
-
- upcase_str_var(cmd_string);
-
- check_multiple_msg(@cmd_string, 4, word_count);
- IF active_tcb^.error_sw THEN
- EXIT;
-
- (*------------------------------------------------------------*)
- (* Loop thru all the messages *)
- (*------------------------------------------------------------*)
-
- x_msg_no := get_next_multiple_msg;
-
- WHILE x_msg_no <> 0 DO
- BEGIN;
-
- (*--------------------------------------------------------*)
- (* Fetch message pointer. Give error if we can't find *)
- (*--------------------------------------------------------*)
-
- msg_ptr := find_msg(x_msg_no);
-
- IF msg_ptr = NIL THEN
- BEGIN;
-
- (*----------------------------------------------------*)
- (* Message not found! Set the error switch *)
- (*----------------------------------------------------*)
-
- active_tcb^.error_sw := TRUE;
-
- (*----------------------------------------------------*)
- (* Send proper message. If more to do then continue *)
- (*----------------------------------------------------*)
-
- IF word_count = 4 THEN
- BEGIN;
- send_message(message_rmc_nf);
- EXIT;
- END
- ELSE
- BEGIN;
- STR(x_msg_no, work_word);
- set_dollar1_parm(@work_word);
- send_message(message_rmc_nf_wp);
- END;
-
- END
-
- ELSE
-
- BEGIN;
-
- (*----------------------------------------------------*)
- (* Message found so export it *)
- (*----------------------------------------------------*)
-
- export_a_msg(msg_ptr);
-
- (*----------------------------------------------------*)
- (* Handle error from export *)
- (*----------------------------------------------------*)
-
- IF active_tcb^.error_sw THEN
- BEGIN;
-
- {$IFDEF DEBUG_1}
- WRITELN('Error set in loop -- ', out_open);
- {$ENDIF}
-
- send_message(message_op_halted);
- export_clean;
- EXIT;
- END;
-
- END;
-
- (*--------------------------------------------------------*)
- (* Get next message *)
- (*--------------------------------------------------------*)
-
- x_msg_no := get_next_multiple_msg;
-
- END; (*----- End read multiple loop ------------------------*)
-
- END; (*----- End Export a certain message ----------------------*)
-
- (*-------------------------------------------------------------------*)
- (* Handle all other letters *)
- (*-------------------------------------------------------------------*)
-
- ELSE
- BEGIN;
-
- (*---------------------------------------------------------------*)
- (* Get just the search portion of the command *)
- (*---------------------------------------------------------------*)
-
- cmd_string := subword(@cmd_string, 3, 0);
-
- (*---------------------------------------------------------------*)
- (* Build search blocks as needed. Exit if error *)
- (*---------------------------------------------------------------*)
-
- set_search(cmd_string, @search_block);
- IF active_tcb^.error_sw THEN
- EXIT;
-
- (*---------------------------------------------------------------*)
- (* Search in the right sequence *)
- (*---------------------------------------------------------------*)
-
- IF NOT search_block.search_direction THEN
- search_block.search_ascend := TRUE;
-
- (*---------------------------------------------------------------*)
- (* Start the search *)
- (*---------------------------------------------------------------*)
-
- search_msg(@search_block);
-
- (*---------------------------------------------------------------*)
- (* If nothing found, tell user and exit *)
- (*---------------------------------------------------------------*)
-
- IF search_block.search_last = NIL THEN
- BEGIN;
- send_message(message_lmc_nf);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*---------------------------------------------------------------*)
- (* Now loop around send the message info, searching for next unti*)
- (*---------------------------------------------------------------*)
-
- WHILE search_block.search_last <> NIL DO
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(search_block.search_last);
- {$ENDIF}
-
- (*-----------------------------------------------------------*)
- (* Export the message *)
- (*-----------------------------------------------------------*)
-
- export_a_msg(search_block.search_last);
-
- (*-----------------------------------------------------------*)
- (* Handle errors from export *)
- (*-----------------------------------------------------------*)
-
- IF active_tcb^.error_sw THEN
- BEGIN;
- send_message(message_op_halted);
- EXIT;
- END;
-
- (*-----------------------------------------------------------*)
- (* Search for next hit *)
- (*-----------------------------------------------------------*)
-
- search_msg(@search_block);
-
- END; (*----- End search loop ----------------------------------*)
-
- END; (*---- End hadling anything but "#" --------------------------*)
-
- END; (*----- End case statement on search type ------------------------*)
-
- END; (*---- End DO_EXPORT subroutine ------------------------------------*)
-
- (*=========================================================================*)
- (* This is the code for exporting via an array *)
- (*=========================================================================*)
-
- PROCEDURE do_export_array;
-
- VAR
- i : BYTE;
-
- BEGIN;
-
- (*---------------------------------------------------------------------*)
- (* Initialize *)
- (*---------------------------------------------------------------------*)
-
- kill_sw := FALSE;
- add_header := TRUE;
-
- {$IFDEF POINT_CHK}
- test_pointer(this_path);
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Set up addressing and prepare to loop *)
- (*---------------------------------------------------------------------*)
-
- WITH this_path^ DO
- BEGIN;
-
- {$IFDEF DEBUG_FILE}
- WRITELN('Export array -- ', path_msg_count);
- {$ENDIF}
-
- i := 0;
-
- (*-----------------------------------------------------------------*)
- (* Loop thru all the messages *)
- (*-----------------------------------------------------------------*)
-
- WHILE i < path_msg_count DO
- BEGIN;
-
- (*-------------------------------------------------------------*)
- (* Bump loop counter *)
- (*-------------------------------------------------------------*)
-
- INC(i);
-
- {$IFDEF DEBUG_FILE}
- WRITELN('Export item -- ', i);
- {$ENDIF}
-
- WITH path_msg_list^[i] DO
- BEGIN;
-
- {$IFDEF POINT_CHK}
- test_pointer(msg_p_i);
- {$ENDIF}
-
- active_tcb^.error_sw := FALSE;
-
- (*---------------------------------------------------------*)
- (* Export this message *)
- (*---------------------------------------------------------*)
-
- export_a_msg(msg_p_i);
-
- {$IFDEF POINT_CHK}
- test_pointer(msg_p_i);
- {$ENDIF}
-
- (*---------------------------------------------------------*)
- (* Mark the message as forwarded *)
- (*---------------------------------------------------------*)
-
- mark_as_forwarded(msg_p_i, msg_p_item, 'O');
-
- (*---------------------------------------------------------*)
- (* Update the database *)
- (*---------------------------------------------------------*)
-
- update_msg(msg_p_i);
-
- (*---------------------------------------------------------*)
- (* Prevent it from being redone *)
- (*---------------------------------------------------------*)
-
- msg_p_i := NIL;
-
- END; (*----- End addressability -----------------------------*)
-
- END; (*----- End loop thru the messages -------------------------*)
-
- END; (*----- End addressability of the path -------------------------*)
-
- END; (*----- End export of a path array ---------------------------------*)
-
- (*=========================================================================*)
- (* Main line of export a message *)
- (*=========================================================================*)
-
- BEGIN;
-
- {$IFDEF DEBUG_FILE2}
- WRITELN('Cmd = ', cmd_string);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Init *)
- (*-----------------------------------------------------------------------*)
-
- FILLCHAR(search_block, SIZEOF(search_block), #0);
- search_block.search_nok := TRUE;
- search_block.search_ascend := TRUE;
-
- out_open := FALSE;
-
- add_header := FALSE;
-
- kill_sw := FALSE;
-
- (*-----------------------------------------------------------------------*)
- (* Get options (if any) *)
- (*-----------------------------------------------------------------------*)
-
- work_word := get_option_string(cmd_string);
-
- upcase_str_var(work_word);
-
- (*-----------------------------------------------------------------------*)
- (* Process options *)
- (*-----------------------------------------------------------------------*)
-
- IF POS('K', work_word) > 0 THEN
- kill_sw := TRUE;
-
- IF POS('H', work_word) > 0 THEN
- add_header := TRUE;
-
- (*-----------------------------------------------------------------------*)
- (* Parse front of command *)
- (*-----------------------------------------------------------------------*)
-
- word_count := WORDS(cmd_string);
-
- (*-----------------------------------------------------------------------*)
- (* Check command format *)
- (*-----------------------------------------------------------------------*)
-
- IF (word_count < 3) AND (this_path = NIL) THEN
- BEGIN;
- send_message(message_not_en);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Assign the file name now *)
- (*-----------------------------------------------------------------------*)
-
- ASSIGN(export_out, subword(@cmd_string, 2, 1));
- {$IFDEF DEBUG_FILE2}
- WRITELN('File = ', subword(@cmd_string, 2, 1));
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Kill ? *)
- (*-----------------------------------------------------------------------*)
-
- work_word := subword(@cmd_string, 1, 1);
- upcase_str_var(work_word);
- IF POS('K', work_word) > 0 THEN
- kill_sw := TRUE;
-
- (*-----------------------------------------------------------------------*)
- (* Execute right subroutine *)
- (*-----------------------------------------------------------------------*)
-
- work_word := subword(@cmd_string, 3, 1);
- exec_char := work_word[1];
-
- work_word := subword(@cmd_string, 4, 1);
- upcase_str_var(work_word);
-
- (*-----------------------------------------------------------------------*)
- (* Execute the export *)
- (*-----------------------------------------------------------------------*)
-
- IF this_path = NIL THEN
- do_export
- ELSE
- do_export_array;
-
- (*-----------------------------------------------------------------------*)
- (* Clean up *)
- (*-----------------------------------------------------------------------*)
-
- export_clean;
-
- (*-----------------------------------------------------------------------*)
- (* If successful, tell user *)
- (*-----------------------------------------------------------------------*)
-
- IF NOT active_tcb^.error_sw THEN
- send_message(message_action_complete);
-
- END;
-
- END.